#!/usr/bin/env python3
#!-*- coding:utf-8 -*-

from neo4j.v1 import GraphDatabase

# 从neo4j导出专家的各领域下论文的数量


uri = "bolt://47.104.244.119:7687"
driver = GraphDatabase.driver(uri, auth=("neo4j", "zhongyi!@#2018"))

index_1 = 0
f = open("D:/scholarPaperCount.txt", 'a', encoding='utf-8')

# f.write("hello\n")

# 专家id，name字典
dict_expert = {}
def print_friends_of():
    with driver.session() as session:
        with session.begin_transaction() as tx:
            for expert in tx.run("match(e:expert) return id(e),e.name"):
                dict_expert[expert["id(e)"]] = expert["e.name"]







def getFosPaperNumById(pId, name, index_1):
    with driver.session() as session:
        with session.begin_transaction() as tx:
            dict1 = {'name': name, 'fos': {}}
            for fos in tx.run("match(e:expert)<-[r:containse]-(f:field) where id(e)={pId} and r.paperCount<>0 return f.name,r.paperCount", pId=pId):
                dict1['fos'][fos["f.name"]] = fos["r.paperCount"]
            print(str(index_1) + str(dict1))
            f.write(str(dict1) + '\n')


print_friends_of()
# getFosPaperNumById(7340)


index_1 = 0
for expert in dict_expert:
    index_1 += 1
    getFosPaperNumById(expert, dict_expert[expert], index_1)
    # if index > 2:
    #     break




